package com.example.stock.business.monitor.logic;

import com.example.stock.excel.Monitor;
import com.example.stock.model.WeekDetail;
import com.example.stock.service.MonthDataService;
import com.example.stock.service.WeekDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 监控股票小于某一价格
 */
@Component
public class WeekCloseDecreaseMonitor implements Trigger{
    @Autowired
    WeekDataService weekDataService;

    @Override
    public boolean trigger(Monitor monitor) {
        List<WeekDetail> weekRawData = weekDataService.getWeekRawData(monitor.getStock());
        if (weekRawData == null) {
            return false;
        }

        Map<String, Double> collect = weekRawData.stream().collect(Collectors.toMap(WeekDetail::getDate, WeekDetail::getClose));

        String mDate = monitor.getExtra();
        return weekRawData.getLast().getClose() <= collect.get(mDate);
    }
}